<template>
	<view class="total">
		<view class="img-a">
			<view class="header">
				<view class="return" @click="goBack()">
					<image style="width: 30px;height: 30px;margin-top: 10px;" src="/static/return.png" alt=""  />
				</view>
			</view>
		</view>
		<view class="login-view">
			<view class="t-login">
				<view class="welcome">
					欢迎登录候鸟养老
				</view>
				<view class="log_style">
					<view class="blue_font">
						更改绑定手机号
					</view>
				</view>
				<view class="">
					<form class="cl">
						<view class="t-a">
							<input type="number" name="phone" placeholder="请输入新手机号码" maxlength="11" v-model="phone" />
						</view>
						<view class="t-a">
							<u-input class="codeInput" placeholder="请输入验证码" v-model="code">
								<template slot="suffix">
									<u-code
									ref="uCode"
									@change="codeChange"
									:seconds="seconds"
									changeText="X秒">
									</u-code>
									<u-button
									id="getCodeButton"
									@tap="getCode"
									:text="tips"
									type="success"
									size="mini"
									>{{tips}}</u-button>
								</template>
							</u-input>
						</view>
						<button class="login_button" @click="changePhone"  style="background-color:#A8A8A8;">确认</button>
					</form>
				</view>
				</view>
		</view>
	</view>
</template>
<script>
import {changeTel} from '@/utils/api.js'
export default {
	data() {
		return {
			token:'',
			phone: '', //手机号码
			pwd: '' ,//密码,
			code:'',
			tips: '发送验证码',
			changePwd:false,
			seconds:60,
			status:""
		};
	},
	methods: {
		changePhone(){
			if(this.phone){
				this.phone=Number(this.phone)
			}
			changeTel({
					admin_phone:this.phone,
			        dxcodess:this.code
			    }).then(res=>{
					if(res.data.meta.status==200){
						uni.setStorageSync('phone',this.phone);
						uni.showToast({ title:"更改手机号成功！", icon: 'none' });
						setTimeout(()=>{
							uni.navigateBack()
						},1000)
					}
					else{
						uni.showToast({ title:res.data.meta.msg, icon: 'none' });
					}
				})
		},
		goBack(){
				uni.navigateBack()
		},
		codeChange(text) {
			this.tips = text;
		},
		getCode() {
			if (this.$refs.uCode.canGetCode) {
			uni.request({
			    url: 'https://www.ghhlkj.com/api/sendSms', 
			    data: {
			        phone:this.phone,
					type:7, 
			    },
				header:{
					'content-type':'application/json'
				},
				method:'POST',
			    success: (res) => {
			        console.log(res.data);
			    }
			});	
			// 模拟向后端请求验证码
			uni.showLoading({
				title: '正在获取验证码'
			})
			setTimeout(() => {
				uni.hideLoading();
				// 这里此提示会被this.start()方法中的提示覆盖
				uni.$u.toast('验证码已发送');
				// 通知验证码组件内部开始倒计时
				this.$refs.uCode.start();
			}, 2000);
			} else {
				uni.$u.toast('倒计时结束后再发送');
			}
		},
		change(e) {
			console.log('change', e);
		}
	}
};
</script>
<style lang="scss" scoped>
.total{
	// padding-top: 20px;
	height: 100%;
	background-color: #f6f6f6;
	position: relative;
}
.codeInput{
		height: 33px;
		margin-top: 30rpx;
		margin-bottom: 50rpx;
		border: 1px solid #e9e9e9;
		border-radius: 8px;
		background-color: #F6F6F6;
		font-size: 28rpx;
		padding: 0 15px;
	}
#getCodeButton{
		margin-top: 0px;
		font-size: 5px;
		width: 80px;
		background-color: #2796f2;
		border-color: #2796f2;
		border-radius: 24px;
		height: 28px;
	}
.txt {
	font-size: 32rpx;
	font-weight: bold;
	color: #333333;
}
.img-a {
	width: 100%;
	height: 450rpx;
	padding-top: 20px;
	background-image: url('/static/img/login_img_bgs.png');
	background-repeat: no-repeat;
	background-size: 100%;
	.header{
		height: 50px;
		line-height: 50px;
		font-size: 20px;
		font-weight: 400;
		color: #FFFFFF;
		display: flex;
		justify-content: space-between;
		padding: 0px 20px;
		.return{
			width: 30px;
			line-height: 50px;
			font-size: 5px;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}
}
.reg {
	font-size: 28rpx;
	color: #fff;
	height: 90rpx;
	line-height: 90rpx;
	border-radius: 50rpx;
	font-weight: bold;
	background: #f5f6fa;
	color: #000000;
	text-align: center;
	margin-top: 30rpx;
}

.login-view {
	background: #FFFFFF;
	border-radius: 5px;
	width: 94%;
	height: 600px;
	margin: auto;
	top: 0px;
	left: 0;
	right: 0;
	bottom: 0;
	margin-top: -150px;
	
}

.t-login {
	width: 600rpx;
	margin: 0 auto;
	font-size: 28rpx;
	padding-top: 80rpx;
	.welcome{
		color:#242424;
		font-size: 25px;
		font-weight: bolder;
	}
	.log_style{
		margin-top: 25px;
		margin-bottom: 30px;
		.blue_font{
			color: #2796f2;
			font-size: 18px;
			font-family: PingFang SC;
			font-weight: 800;
		}
		.tishi{
			margin-top: 10px;
			margin-bottom: 50px;
			font-size: 12px;
			font-family: PingFang SC;
			font-weight: 500;
			color: #868686;
		}
	}
}

.t-login button {
	margin-top: 30px;
	font-size: 35rpx;
	background: #2796f2;
	color: #fff;
	line-height: 88rpx;
	font-weight: bold;
	width: 462rpx;
	height: 88rpx;
	border-radius: 44rpx;
	margin-top: 100rpx;
}

.t-login input {
	margin-top: 15px;
	height: 90rpx;
	line-height: 90rpx;
	margin-bottom: 50rpx;
	border: 1px solid #e9e9e9;
	border-radius: 10px;
	background-color: #F6F6F6;
	font-size: 28rpx;
	padding: 0 15px;
}

.t-login .t-a {
	position: relative;
}

.t-b {
	text-align: left;
	font-size: 42rpx;
	color: #ffffff;
	padding: 130rpx 0 0 70rpx;
	font-weight: bold;
	line-height: 70rpx;
}

.t-login .t-c {
	position: absolute;
	right: 22rpx;
	top: 22rpx;
	background: #5677fc;
	color: #fff;
	font-size: 24rpx;
	border-radius: 50rpx;
	height: 50rpx;
	line-height: 50rpx;
	padding: 0 25rpx;
}

.t-login .t-d {
	text-align: center;
	color: #999;
	margin: 80rpx 0;
}

.t-login .t-e {
	text-align: center;
	width: 250rpx;
	margin: 80rpx auto 0;
}

.t-login .t-g {
	float: left;
	width: 50%;
}

.t-login .t-e image {
	width: 50rpx;
	height: 50rpx;
}

.t-login .t-f {
	text-align: center;
	margin: 150rpx 0 0 0;
	color: #666;
}

.t-login .t-f text {
	margin-left: 20rpx;
	color: #aaaaaa;
	font-size: 27rpx;
}

.t-login .uni-input-placeholder {
	color: #aeaeae;
}

.cl {
	zoom: 1;
	.forger{
		float: right;
		margin-top: -10px;
	}
	.agreen{
		margin-top: 65px;
		display: flex;
			.radios{
				width: 28px;
				height: 20px;
				margin-right:10px ;
			}
			.texts{
				
			}
		
	}
}
.cl:after {
	clear: both;
	display: block;
	visibility: hidden;
	height: 0;
	content: '\20';
}
</style>
